/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reportcenter.datasource.ui;

import javax.swing.JComponent;
import org.springframework.richclient.form.AbstractForm;
import org.springframework.richclient.form.builder.TableFormBuilder;
import reportcenter.datasource.dominio.DataSource;

/**
 *
 * @author renan
 */
public class DataSourceForm extends AbstractForm{
    
    private JComponent nameField;
    
    public DataSourceForm(DataSource dataSource){
        super(dataSource);
        setId("dataSourceForm");
    }

    @Override
    protected JComponent createFormControl() {
        TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());

        formBuilder.setLabelAttributes("colGrId=label colSpec=right:pref");

        formBuilder.addSeparator(getMessage("dataSourceForm.separator.title1"));
        formBuilder.row();
        nameField = formBuilder.add("name","colSpan=1 align=left")[1];
        formBuilder.row();
        
        
//        //Criar bind em formato de lista para o atributo idD(DataSource)
//        SwingBindingFactory f = new SwingBindingFactory(getFormModel());
//        List<DBDriver> listDS = ((DBDriverConfig) getApplicationContext().getBean("dbDriverConfig")).getAvaiableDrivers();
//        ValueModel listDSVm = new ValueHolder(listDS);
//
//        Map m = new HashMap();
//        m.put(ListSelectionDialogBinder.SELECTABLE_ITEMS_HOLDER_KEY, listDSVm);
//        m.put(ListSelectionDialogBinder.LABEL_PROVIDER_KEY, new LabelProvider() {
//
//            public String getLabel(Object item) {
//                DBDriver bean = (DBDriver) item;
//                return bean == null ? "" : bean.getDescription();
//            }
//        });
//        
//        m.put(ListSelectionDialogBinder.TITLE_KEY_KEY, "Escolha o Driver JDBC");
//        m.put(ListSelectionDialogBinder.FILTERED_KEY, Boolean.TRUE);
//        m.put(ListSelectionDialogBinder.DESCRIPTION_KEY_KEY, "Filtro(Desrição/URI Pattern)");
//        m.put(ListSelectionDialogBinder.FILTER_PROPERTIES_KEY,
//                                             new String[] { "description","uripattern" });
//
//        formBuilder.add(getBindingFactory().createBinding("driver", m),"colSpan=1");
        
        
        
        
        
        formBuilder.add("driver","colSpan=1 align=left");
        
        formBuilder.row();
//        formBuilder.addTextArea("uri");
        formBuilder.add("uri","colSpan=1 align=left");
        formBuilder.row();
        formBuilder.row();
        formBuilder.add("usu","colSpan=1 align=left");
        formBuilder.row();
        formBuilder.addPasswordField("pass","colSpan=1 align=left");
        formBuilder.row();
        formBuilder.add("minpool","colSpan=1 align=left");
        formBuilder.row();
        formBuilder.add("maxpool","colSpan=1 align=left");

        return formBuilder.getForm();
    }
    
    public boolean requestFocusInWindow() {
        return nameField.requestFocusInWindow();
    }

}
